% eyelid_script
function run_eyelid(input_folder)
%% Open the target folder
ny_folder = dir(input_folder);
ny_folder = ny_folder(3:end);

%% For each image, open the corresponding iris file
h = waitbar(0,sprintf('%d of %d finished',0,length(ny_folder)));
guesses = cell(length(ny_folder),1);
for i = 1:length(ny_folder)
    ny_folder(i).name
    waitbar(double(i)/length(ny_folder),h,sprintf('%d of %d finished',i,length(ny_folder)));
    filepath = fullfile(input_folder,ny_folder(i).name);
    
    I = imread(filepath);
    [center,radius] = circularhough(I,.5,false);
    eyelid_points = detect_eyelid(I,[center(2) center(1)],radius,false);
    
    %[px, py] = circlepoints(radius);
    %figure(i); imshow(I); hold on; plot(py+center(2),px+center(1));
    
    %plot(eyelid_points(:,1),eyelid_points(:,2),'ro');
    
    data = zeros(11,3);
    data(1,:) = [center(2) center(1) radius];
    data(2:end,1:2) = eyelid_points;
    guess.filepath = filepath;
    guess.data = data;
    guesses{i} = guess;
    
    %guesspath = fullfile('guesses',[ny_folder(i).name '.guess']);
    %dlmwrite(guesspath, data, 'delimiter', '\t')
end
save(input_folder,'guesses');
close(h);
end